package com.honeyms.project.monitor.job.task;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.honeyms.project.blog.blogcomment.service.IBlogCommentService;
import com.honeyms.project.blog.blogcontent.service.IBlogContentService;
import com.honeyms.project.blog.blogcontentdetail.domain.BlogContentDetail;
import com.honeyms.project.blog.blogcontentdetail.domain.Validation;
import com.honeyms.project.blog.blogcontentdetail.service.IBlogContentDetailService;
import com.honeyms.project.blog.blogrecommend.service.IBlogRecommendService;
import com.honeyms.project.system.config.domain.Config;
import com.honeyms.project.system.config.service.IConfigService;
import com.honeyms.project.system.userdetail.service.IUserDetailService;

/**
 * blog任务
 * @author honey
 * @version 创建时间：2020年10月19日 下午1:10:07
 */
@Component("blogTask")
public class BlogTask {

	@Autowired
	private IBlogContentDetailService blogContentDetailService;
	
	@Autowired
	private IBlogContentService blogContentService;
	
	@Autowired
	private IUserDetailService userDetailService;
	
	@Autowired
	private IBlogRecommendService blogRecommendService;
	
	@Autowired
	private IBlogCommentService blogCommentService;

    @Autowired
    private IConfigService configService;
	
	 /**
     * 效验用户点赞收藏
     */
    public void validationZanAndFavorites()
    {
    	System.out.println("效验点赞收藏!");
        List<Validation> listzan=blogContentDetailService.validationZan();
        if (!listzan.isEmpty()) {
        	 for (Validation validation : listzan) {
             	System.out.println(validation);
     			BlogContentDetail zan = blogContentDetailService.selectBlogContentDetailById(validation.getId());
     			zan.setZan(validation.gethZong());
     			blogContentDetailService.updateBlogContentDetail(zan);
     		}
		}
       
        List<Validation> listfovrites = blogContentDetailService.validationFavorites();
        if (!listfovrites.isEmpty()) {
        	for (Validation validation : listfovrites) {
            	System.out.println(validation);
            	BlogContentDetail favorites = blogContentDetailService.selectBlogContentDetailById(validation.getId());
            	favorites.setFavorites(validation.gethZong());
            	blogContentDetailService.updateBlogContentDetail(favorites);
    		}
		}
    }
    
    /**
     * 初始化签到
     */
    public void refreshsign() 
    {
    	userDetailService.refreshsign();
    }
    
    /**
     * 初始化猜你喜欢
     */
    public void refreshguessyoulike() 
    {
    	blogRecommendService.refreshguessyoulike();
    }
    
    /**
     * 初始化猜你喜欢
     */
    public void refreshcommentandcontentcount() 
    {
    	String cv = configService.selectConfigByKey("sys.blog.commentcount");
    	String count = blogCommentService.selectCounte(0L)+":"+blogCommentService.selectCounte(1L)+":"+blogCommentService.selectCounte(2L)+":"+blogCommentService.selectCountd(6L)+":"+blogCommentService.selectCountd(29L);
    	Config config = new Config();
    	config.setConfigKey("sys.blog.commentcount");
    	config.setConfigValue(count);
    	if ("".equals(cv)) {
    		config.setRemark("今日评论:昨日评论:前日评论:最近7天评论:最近30天评论");
    		config.setCreateTime(new Date());
    		config.setConfigName("评论统计");
    		config.setConfigType("Y");
			configService.insertConfigBySystem(config);
		} else {
			configService.updateConfigByKey(config);
		}
    	
    	String cv1 = configService.selectConfigByKey("sys.blog.contentcount");
    	String count1 = blogContentService.selectCounte(0L)+":"+blogContentService.selectCounte(1L)+":"+blogContentService.selectCounte(2L)+":"+blogContentService.selectCountd(6L)+":"+blogContentService.selectCountd(29L);
    	config = new Config();
    	config.setConfigKey("sys.blog.contentcount");
    	config.setConfigValue(count1);
    	if ("".equals(cv1)) {
    		config.setRemark("今日发帖:昨日评发帖:前日发帖:最近7天发帖:最近30天发帖");
    		config.setCreateTime(new Date());
    		config.setConfigName("帖子统计");
    		config.setConfigType("Y");
    		configService.insertConfigBySystem(config);
    	} else {
    		configService.updateConfigByKey(config);
    	}
    	
    	
    	
    }
}
